function diff(str1, str2) {
    str1 = str1.replace(/\s*/g, "")
    str2 = str2.replace(/\s*/g, "")
    // 计算两个字符串长度
    const len1 = str1.length;
    const len2 = str2.length;
    // 创建装载数组
    const dif = [];
    for (let i = 0; i < len1 + 1; i++) {
        dif.push(new Array(len2 + 1));
    }
    // 赋初始值
    for (let i = 0; i <= len1; i++) {
        dif[i][0] = i;
    }
    for (let i = 0; i <= len2; i++) {
        dif[0][i] = i;
    }
    // 计算两个字符串是否一样
    const ch1 = str1.split('');
    const ch2 = str2.split('');
    let temp;
    for (let i = 1; i <= len1; i++) {
        for (let j = 1; j <= len2; j++) {
            if (ch1[i - 1] == ch2[j - 1]) {
                temp = 0;
            } else {
                temp = 1;
            }
            // 取最小值
            const temp1 = dif[i - 1][j - 1] + temp;
            const temp2 = dif[i][j - 1] + 1;
            const temp3 = dif[i - 1][j] + 1;

            dif[i][j] = Math.min(temp1, temp2, temp3);
        }
    }
    // console.log(dif[len1][len2])
    // 计算相似度
    // const similarity = 1 - dif[len1][len2] / Math.max(str1.length, str2.length);
    const similarity = (Math.max(str1.length, str2.length) - dif[len1][len2]) / Math.min(str1.length, str2.length);
    return similarity;
}

str1 = 'vivo T1 8GB+128GB 电光青 骁龙778G芯片 44W疾速闪充 120Hz刷新率 5000mAh大电池 6400万高清主摄 5G双模'
str2 = 'vivo iQOO 9 5G新品 KPL电竞专用手机 12+512G 赛道版 E5超视网膜屏+全新一代骁龙8+独显芯片Pro+全感操控系统3.0+120W超快闪充'
str3 = 'vivo Y32 6GB+128GB 雾夜黑 5000mAh大电池18W快充骁龙八核处理器后置1300万清晰影像新品y32'
str4 = 'vivo iQOO U5x 新品手机 4+128G 星光黑 高通骁龙680处理器+5000mAh超大电池+6.51英寸高清大屏幕+800万高清自拍'
str5 = 'vivo Y71t 8GB+128GB 午夜蓝 天玑810芯片 2k-OLED超清屏幕 44W疾速闪充 6400万超清影像系统 屏幕指纹 5G双模'
str6 = 'vivo iQOO 9 5G新品 KPL电竞专用手机 12+512G 传奇版 E5超视网膜屏+全新一代骁龙8+独显芯片Pro+全感操控系统3.0+120W超快闪充'
str7 = 'vivo iQOO 9 Pro 5G新品 KPL电竞专用手机 12+512G 赛道版 2K E5超视网膜屏+超声波3D广域指纹+全新一代骁龙8+独显芯片Pro+全新微云台双主摄'


str8 = 'vivo Y31s标准版 8GB+128GB 宝石红'
str9 = 'vivo Y31s标准版 8GB+128GB 皓月白'
str10 = '【预约】ivo T2新品'
str11 = 'iQOO 9 Pro 12GB+256GB 传奇版'
str12 = 'iQOO 9 Pro 12GB+512GB 传奇版'
jixing = 'vivoiQOO 9'
// jixing = jixing.replace('vivo', '')
// console.log(jixing);
// console.log(diff(str1, jixing));
// console.log(diff(str2, jixing));
// console.log(diff(str3, jixing));
// console.log(diff(str4, jixing));
// console.log(diff(str5, jixing));
// console.log(diff(str6, jixing));
// console.log(diff(str7, jixing));
// console.log(diff(str8, jixing));
// console.log(diff(str9, jixing));
// console.log(diff(str10, jixing));
// console.log(diff(str11, jixing));
// console.log(diff(str12, jixing));
// console.log(diff(str13, jixing));
// console.log(diff(str1,jixing));


var brand = (str1, str2) => {
    let x = str1.split(" ");
    let y = str2.split(" ");
    let ans = 0;
    let ret = 0;
    for (let i = 0; i < x.length; i++) {
        for (let j = 0; j < y.length; ++j) {
            if (x[i] === undefined || y[j] === undefined) {
                continue;
            }
            if (x[i].indexOf(y[j]) >= 0 || y[j].indexOf(x[i]) >= 0) {
                ans++;
                ret += Math.min(x[i].length, y[j].length);
            }
        }
    }
    console.log(ans);
    return [ans, ret]
}
mi = '小米Redmi Note9 Pro'
let test = [
    {

        price: 1499,
        comment: '1100+',
        skuname: '小米(MI)Redmi Note 9 Pro 8GB+256GB 静默星空 移动电信联通全网通5G手机',
        url: 'https://product.suning.com/0010328612/12297140170.html',
        img: 'https://imgservice4.suning.cn/uimg1/b2c/image/LeHy6Zcv4z1oH6SXBdSycg.jpg_400w_400h_4e',
        logourl: 'http://localhost:8002/ShopLogo/sn.png'
    },
    {
        price: 1599,
        comment: '1',
        skuname: '[官方旗舰店]小米Redmi Note 10 Pro 5G全网通 8GB+128GB 幻青 天玑1100 5000mAh大电量 67W闪充 120Hz变速屏 5G全网通',
        url: 'https://product.suning.com/0010328335/12293318502.html',
        img: 'https://imgservice1.suning.cn/uimg1/b2c/image/-lMNq-5BhgRg8JTyJ4naYw.jpg_400w_400h_4e',
        logourl: 'http://localhost:8002/ShopLogo/sn.png'
    },
    {

        price: 2099,
        comment: '80+',
        skuname: '小米(MI) Redmi Note 11 Pro+ 8GB+256GB 神秘黑境 移动电信联通全网通5G手机',
        url: 'https://product.suning.com/0010328612/12339661685.html',
        img: 'https://imgservice5.suning.cn/uimg1/b2c/image/dc2RJ9nwHI3shV-BeRWYGA.jpg_400w_400h_4e',
        logourl: 'http://localhost:8002/ShopLogo/sn.png'

    },
    {

        price: 3499,
        comment: '1.8万+',
        skuname: '小米(MI)小米11 12+256GB 烟紫(素皮) 新一代5G芯片 骁龙888 4600mAh大电量 1亿像素计算摄影 小米新品旗舰机 安卓大屏游戏机',
        url: 'https://product.suning.com/0000000000/12200356642.html',
        img: 'https://imgservice5.suning.cn/uimg1/b2c/image/q-Jri6kAmGmOS77XGlLPSA.jpg_400w_400h_4e',
        logourl: 'http://localhost:8002/ShopLogo/sn.png'
    }, {

        price: 849,
        comment: '600+',
        skuname: '小米(MI)Redmi 红米 9A 4GB+128GB 晴空蓝 移动电信联通全网通4G手机',
        url: 'https://product.suning.com/0010328612/12301095553.html',
        img: 'https://imgservice5.suning.cn/uimg1/b2c/image/MPcn7fhZXKUvkXoH4SPm7g.jpg_400w_400h_4e',
        logourl: 'http://localhost:8002/ShopLogo/sn.png'
    },
    {

        price: 1149,
        comment: '3300+',
        skuname: '小米(MI) Redmi Note 10 6GB+128GB 竹石青 移动电信联通全网通5G手机',
        url: 'https://product.suning.com/0010328612/12294882311.html',
        img: 'https://imgservice3.suning.cn/uimg1/b2c/image/r01Kg5kLdVXD6sP8yo7y5w.jpg_400w_400h_4e',
        logourl: 'http://localhost:8002/ShopLogo/sn.png'
    },
    {

        price: 1379,
        comment: '10+',
        skuname: '[官方旗舰店]小米Redmi Note 10 5G 8+256GB 月影银 5000mAh大电量 天玑700八核高性能芯片 4800万高清相机 FHD+全高清屏 双5G待机',
        url: 'https://product.suning.com/0010328335/12294275783.html',
        img: 'https://imgservice3.suning.cn/uimg1/b2c/image/o3GNhxcmS7LF3ch-NOMGxQ.jpg_400w_400h_4e',
        logourl: 'http://localhost:8002/ShopLogo/sn.png'
    },
]

test.sort((a, b) => {
    let aa = brand(a.skuname, mi)
    let bb = brand(b.skuname, mi)
    if (aa[0] == bb[0]) {
        return bb[1] - aa[1]
    }
    else {
        return bb[0] - aa[0]
    }
})
test.forEach(e => {
    console.log(e.skuname);
})

